#pragma once

/*
*	Purpose:
*		This class manages the classes that compose the Editor, interweaving all of them so that they work well together.
*		It includes the ClipPlane, SelectionBox, RoomManager, and the RoomCreator.  (Probably more, depending on how up-to-date this comment is.)
*		
*/

/*
*	TODO:
*		Actually build the classes
*			SelectionBoxHandler		50% (buggy)
*
*			RoomGrid				50% (horrible algorithm)
*			RoomManager				70% (removing rooms)
*			RoomCreator				40% (only handles basic room creation, no paths, no mirroring, etc)
*
*			EditorEventHandler		60% (just need to add necessary events)
*
*/

#include "ClippingPlane.h"
#include "Camera.hpp"
#include "SelectionBoxHandler.hpp"
#include "RoomGrid.hpp"
#include "RoomManager.hpp"
#include "RoomCreator.hpp"
#include "EditorEventHandler.hpp"
#include "MapManager.hpp"
#include "GUIManager.h"
#include "EditorGUI.hpp"
#include "Minimap.h"

class EditorEventHandler;
class RoomGrid;
class EditorGUI;

class EditorManager
{
// Handles events
friend class EditorEventHandler;
friend class RoomGrid;
friend class EditorGUI;

private:
	// GUI etc
	EditorGUI*				m_pEditorGUI;			// handles the GUI
	ClippingPlane*			m_pClipPlane;			// our clipping plane
	Camera*					m_pCamera;				// our camera
	SelectionBoxHandler*	m_pSelectionBoxHandler;	// the selection box handler

	// Rooms
	RoomGrid*				m_pRoomGrid;			// our grid that displays rooms
	RoomManager*			m_pRoomManager;			// manages rooms; ie: export to Lua
	RoomCreator*			m_pRoomCreator;			// used to create rooms
	Room				   *m_pRoomA, *m_pRoomB,	// these two rooms are used for creating paths
						   *m_pMouseOverRoom;		// the room that the mouse is over

	bool m_CreateRoom,	// do we need to create a room?
		 m_DrawSelectionBox, // draw the selection box?
	     m_CreatePath, // do we need to create a path?
		 m_PathRiver, // is our path a river?
		 m_EnableRoomMovement, // can we move rooms?
		 m_RemoveRoom,	// should we remove m_pRoomA?
		 m_MergePathListsInRoomManager; // this bool tells the room manager under which list it should add the new path to.
										// this is done to avoid an infinite loop when we regenerate all the paths when moving a room

	int  m_ActiveAlgorithm, // the current algorithm used to generate the room
	     m_ActiveImgID, // current imgID used to generate the room
		 m_RoomSelectionStart, // this controls at what point the iterator begins for "room selection"
		 m_PathWidth;	// the number of tiles wide that the path is
		 


	double m_Density, // the new density of the room
		m_SmoothPath; // should the path be curvey and jagged or should it take the shortest distance to the room?  how jagged should it be?

	// Events
	EditorEventHandler*		m_pEditorEvents;		// used to handle events

	// Minimap
	Minimap*				m_pMinimap;

	// Data
	MapData*				m_pMapData;				// mapScriptPath, mapName, etc


public:
	EditorManager();
	~EditorManager();
	
	// Handle events
	void HandleEvents(SDL_Event* event);

	// Performs tasks such as room generation
	void Update();

	// Renders the editor
	void Render(const SDL_Event& event);
};